package com.bravo.sms.listener;

import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @author: Yuyong
 * @create: 2019-08-27 16:18
 **/

/**
 * 短信监听类
 */
@Component
@RabbitListener(queues = "sms")
@Slf4j
public class SmsListener {

    @Autowired
    private SmsUtil smsUtil;

    @RabbitHandler
    public void sendSms(Map<String,String> message){
        log.info("手机号:{}",message.get("mobile"));
        log.info("验证码:{}",message.get("code"));
        String result = smsUtil.sendSms(message.get("mobile"), message.get("code"), "15");
        if ("0".equals(result)){
            log.info("验证码发送成功");
        }else{
            log.info("验证码发送失败");
        }
    }


}
